package is.pricewatcher;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;

public class MainActivity extends Activity {

	public final static String REGISTER_RESULT = "is.pricewatcher.REGISTER_RESULT";
	public final static String UPC = "is.pricewatcher.UPC";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		Log.i(MainActivity.class.toString(), "onCreate");
		
//		//Start the location fetching
//		ComponentName locationServiceName = new ComponentName(getPackageName(),
//				LocationService.class.getName());
//		startService(new Intent().setComponent(locationServiceName));
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

//	@Override
//	protected void onResume() {
//		super.onResume();
//		Log.i(MainActivity.class.toString(), "onResume");
//		Intent intent = getIntent();
//		String message = intent.getStringExtra(MainActivity.REGISTER_RESULT);
//		Log.i("REGISTER_RESULT", message);
//		TextView result = (TextView) findViewById(R.id.resultText);
//		result.setText(message);
//	}

	public void onScan(View view) {
		IntentIntegrator integrator = new IntentIntegrator(MainActivity.this);
//		integrator.addExtra("SCAN_WIDTH", 800);
//		integrator.addExtra("SCAN_HEIGHT", 200);
		integrator.addExtra("RESULT_DISPLAY_DURATION_MS", 500L);
		integrator.addExtra("PROMPT_MESSAGE", "Custom prompt to scan a product");
		integrator.initiateScan(IntentIntegrator.PRODUCT_CODE_TYPES);

		// Intent intent = new Intent(this, ScannerActivity.class);
		// startActivity(intent);
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent intent) {
		IntentResult result = IntentIntegrator.parseActivityResult(requestCode,
				resultCode, intent);
		if (result != null) {
			String upc = result.getContents();
			if (upc != null) {
				Intent i = new Intent(this, ResultActivity.class);
				i.putExtra(UPC, upc);
				startActivity(i);
			} else {
				// showDialog(R.string.result_failed,
				// getString(R.string.result_failed_why));
			}
		}
	}
}